package shakespeare;

import java.text.DecimalFormat;

public class WordEntity implements Comparable<WordEntity> {
	private String key;
	private Integer count;
	private int tf;
	private double tfw;
	private int df;
	private double idf;
	private double weight;

	public WordEntity(String key, Integer count) {
		this.key = key;
		this.count = count;
	}

	/**
	 * 
	 * @param key
	 *            关键字
	 * @param count
	 *            数量
	 * @param tf
	 *            频率
	 * @param tfw
	 *            平滑后频率
	 */
	public WordEntity(String key, Integer count, int tf, double tfw) {
		this.key = key;
		this.count = count;
		this.tf = tf;
		this.tfw = tfw;
	}

	public WordEntity(String key, Integer count, int tf, double tfw, int df,
			double idf, double weight) {
		this.key = key;
		this.count = count;
		this.tf = tf;
		this.tfw = tfw;
		this.df = df;
		this.idf = idf;
		this.weight = weight;
	}

	public int compareTo(WordEntity o) {
		int cmp = count.intValue() - o.count.intValue();
		return (cmp == 0 ? key.compareTo(o.key) : -cmp);
		// 只需在这儿加一个负号就可以决定是升序还是降序排列 -cmp降序排列，cmp升序排列
		// 因为TreeSet会调用WorkForMap的compareTo方法来决定自己的排序
	}

	@Override
	public String toString() {
		// return "WordEntity [key=" + key + ", count=" + count + ", tf=" + tf
		// + ", tfw=" + tfw + ", df=" + df + ", idf=" + idf + ", weight="
		// + weight + "]";
		return key + "," + count + "," + tf + "," + fomatdouble(tfw) + "," + df + "," + fomatdouble(idf)
				+ "," + fomatdouble(weight);
	}

	public String getKey() {
		return key;
	}

	public Integer getCount() {
		return count;
	}

	public int getTf() {
		return tf;
	}

	public void setTf(int tf) {
		this.tf = tf;
	}

	public double getTfw() {
		return tfw;
	}

	public void setTfw(double tfw) {
		this.tfw = tfw;
	}

	public int getDf() {
		return df;
	}

	public void setDf(int df) {
		this.df = df;
	}

	public double getIdf() {
		return idf;
	}

	public void setIdf(double idf) {
		this.idf = idf;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public void setCount(Integer count) {
		this.count = count;
	}

	public double getWeight() {
		return weight;
	}

	public void setWeight(double d) {
		this.weight = d;
	}
	public static String fomatdouble(Double d) {
		DecimalFormat df = new DecimalFormat("#.00");
		return "" + df.format(d);
	}
}
